
#include "EffectsManager.h"
#include "TaskDestroyEffect.h"


EffectsManager * EffectsManager::mInstance = 0;
int EffectsManager::mIdentifiers = 0;

int EffectsManager::GetNextIdentifier()
{
	return mIdentifiers++;
}

EffectsManager::EffectsManager( Ogre::SceneManager * sceneMgr, Control * ctrl ) : mSceneManager(sceneMgr), mCtrl(ctrl)
{
	mInstance = this;
}

EffectsManager * EffectsManager::Get()
{
	return mInstance;
}

void EffectsManager::AddEffect( std::string const & nombre, Ogre::Vector3 const & pos, int duracion )
{
	int id = GetNextIdentifier();
	std::string idstr = "ef";
	idstr += boost::lexical_cast<std::string>(id);
	Ogre::SceneNode * nodo = mSceneManager->getRootSceneNode()->
		createChildSceneNode(idstr, pos);
	Ogre::ParticleSystem * psys = mSceneManager->createParticleSystem(
		idstr, nombre);
	nodo->attachObject(psys);
	ITask::Ptr tarea(new TaskDestroyEffect(mSceneManager, nodo, psys));
	mCtrl->GetScheduler().AddTask(tarea, duracion);
}